package Demo.ClassPath.Impl;

import Demo.ClassPath.Read;

import java.io.IOException;
import java.nio.file.*;

/**
 * 读取jar包
 */
public class JarRead implements Read {
    private Path absolutePath;

    public JarRead(String path) {
        //获取绝对路径
        this.absolutePath = Paths.get(path).toAbsolutePath();
    }
    @Override
    public byte[] readClass(String className) throws IOException {
        try(FileSystem jarFiles = FileSystems.newFileSystem(absolutePath,null)) {
            return Files.readAllBytes(jarFiles.getPath(className));
        }
    }
}
